Skip to main content

Loops

Loop nodes allow a workflow to repeat part of its execution until a specified condition is no longer satisfied. Instead of duplicating workflow steps, loops execute the same sequence multiple times while evaluating a predicate after each iteration. Loops are useful for iterative processing, polling operations, and retry-like business logic.

What is a Loop?

A loop repeatedly executes a section of a workflow. Conceptually:
Execution continues until the loop condition evaluates to False.

Why Use Loops?

Many business processes require repeated execution. Examples include:
  • processing collections
  • polling external services
  • waiting for a condition
  • batch operations
  • iterative validation
Without loops, the workflow would require duplicated nodes.

Loop Flow

A loop creates a cycle within the workflow.
Each iteration uses the current workflow context.

Loop Predicate

Like condition nodes, loop nodes evaluate a predicate. Conceptually:
The predicate determines whether another iteration should execute.

Using Workflow Variables

Loop predicates typically evaluate workflow variables. Example:
Variables are updated during each iteration.

Example

Suppose a workflow processes items in a collection.
The workflow continues until every item has been processed.

Polling Example

Loops can also monitor external systems.
Once the external process finishes, the workflow exits the loop.

Loops vs Retry

Although they appear similar, loops and retries solve different problems. Retries automatically recover from failures. Loops intentionally repeat workflow logic.

Nested Loops

Large workflows may contain multiple loops.
While supported conceptually, deeply nested loops should be used carefully to maintain readability.

Loop Exit

Every loop must eventually terminate.
A loop without a terminating condition may execute indefinitely.

Preventing Infinite Loops

A good loop should always modify the state that controls its predicate. Example:
Without state changes, the loop may never exit.

Workflow Context

Each iteration shares the same workflow context.
Variables accumulate across iterations unless explicitly reset.

Common Use Cases

Loop nodes are useful for:
  • processing batches
  • iterating over records
  • pagination
  • scheduled polling
  • incremental processing
  • approval retries
  • repeated validation

Best Practices

  • Ensure every loop has a clear exit condition.
  • Update workflow variables during each iteration.
  • Keep loop bodies focused on one task.
  • Avoid deeply nested loops.
  • Consider retries instead of loops for transient failures.
  • Monitor long-running loops in production workflows.

Summary

Loop nodes enable BindAI workflows to repeat execution while a predicate remains true. They provide a clean, reusable mechanism for iterative business logic while sharing workflow context across every iteration. Well-designed loops simplify workflows and eliminate unnecessary duplication.